#include "Rules.h"
using namespace std;

//This determines if the given card is a seven. We loop this to find legal
//cards for normRules
bool normRules::isSeven(Card card){
        if(card.getRank() == SEVEN) return true;
        else return false;
}

//This the main wrapper we use to test if a given card is legal or not under
//the normal rules. Essentially, if the card isadjacent to any card on the
//table, its legal. In addition, if the card is a seven, it is legal.
bool Rules::isAdjacent(Card card){
        if(card.getSuit() == CLUB){
                for(list<Card>::iterator i = playedClubs.begin(); i != playedClubs.end(); i++){
                        if(i->rank_ - 1 == card.rank_) return true;
                        if(i->rank_ + 1 == card.rank_) return true;
                }
        }
        else if(card.getSuit() == DIAMOND){
                for(list<Card>::iterator i = playedDiamonds.begin(); i != playedDiamonds.end(); i++){
                        if(i->rank_ - 1 == card.rank_) return true;
                        if(i->rank_ + 1 == card.rank_) return true;
                }
        }
        else if(card.getSuit() == HEART){
                 for(list<Card>::iterator i = playedHearts.begin(); i != playedHearts.end(); i++){
                        if(i->rank_ - 1 == card.rank_) return true;
                        if(i->rank_ + 1 == card.rank_) return true;
                }
        }
        else if(card.getSuit() == SPADE){
                for(list<Card>::iterator i = playedSpades.begin(); i != playedSpades.end(); i++){
                        if(i->rank_ - 1 == card.rank_) return true;
                        if(i->rank_ + 1 == card.rank_) return true;
                }
        }
        return false;
}

bool normRules::isLegal(Card card){
        if(isSeven(card) || isAdjacent(card)) return true;
        else return false;
}


//determines whether the given card is the startcard or not (normRules)
bool normRules::isStartCard(Card card){
        if(card.getSuit() == SPADE && card.getRank() == SEVEN) return true;
        else return false;
}

//Determines if the given card is the same number as the previously played card
//(altrules)
bool altRules::isNum(Card card){
        if(card.getRank() == prevCard.getRank()) return true;
        else return false;
}

//The altrules islegal function. This will return true if the card has the same
//number as the previously played card, or isAdjacent to the previously played
//card
bool altRules::isLegal(Card card){
        if(isNum(card) || isAdjacent(card)) return true;
        else return false;
}

//Determines if the given card is the start card - altRules
bool altRules::isStartCard(Card card){
        if(card.getRank() == EIGHT && card.getSuit() == HEART) return true;
        else return false;
}


